<template>
  <div class="WorkLog-container">
    <!-- 栅格 输入框 和按钮 -->
    <el-row class="filterCondition">
      <el-form label-width="82px" label-position="right" ref="formLabelAlign"  :model="formLabelAlign">
        <el-form-item prop="customerName" label=" 客户" >
          <el-input v-model="formLabelAlign.customerName" placeholder="姓名/ID/手机号均可"></el-input>
        </el-form-item>
        <el-form-item prop="userName" label=" 顾问">
          <el-input v-model="formLabelAlign.userName" placeholder="输入顾问的姓名"></el-input>
        </el-form-item>
        <el-form-item prop="assistantName" label=" 助理" v-show="ShowDaoChu">
          <el-input v-model="formLabelAlign.assistantName" placeholder="输入助理的姓名"></el-input>
        </el-form-item>
        <el-form-item label="时间">
          <el-select v-model="formLabelAlign.dayType" id="time" @change="holderQuJian" placeholder="时间" >
            <el-option
              v-for="item in timeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="completeTime" label="时间区间" v-show="isShow">
          <div class="block" >
            <el-date-picker
              v-model="completeTime"
              type="daterange"
              format="yyyy/MM/dd"
              value-format="yyyy/MM/dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item class="BTN">
        <el-button style="background-color:#c73e3a;color:#fff" @click="checkCus" class="check">查询</el-button>
        <el-button style="background-color:#008c5e;color:#fff" @click="PushToEditLog" class="check">编写日志</el-button>
        <el-button style="background-color:#f1af00;color:#fff" @click="excelDoor" v-show="ShowDaoChu" class="check">导出</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <!-- table -->
    <el-table  :data="tableData" style="width: 100%" >
      <el-table-column label="归属" width="200">
        <template slot-scope="scope">
          <p class="ell">{{ scope.row.parentName2 }}{{scope.row.parentName3 | panKong}}{{scope.row.parentName4 |panKong}}</p>
        </template> 
      </el-table-column>
      <el-table-column prop="userName" label="顾问" ></el-table-column>
      <el-table-column prop="customerName" label="客户" ></el-table-column>
      <el-table-column prop="assistantName" label="进件助理" ></el-table-column>
      <el-table-column prop="workType" label="工作类型" ></el-table-column>
      <el-table-column  label="进度" >
        <template slot-scope="scope">
          <span v-if="scope.row.state == '征信不符' " style='color:#C73E3A'>{{ scope.row.state}}</span>
          <span v-else-if=" scope.row.state == '已签约'||scope.row.state == '已上门'||scope.row.state == '收款'  || scope.row.state == '待签约'|| scope.row.state == '已放款'|| scope.row.state == '审核中'" style='color:#5BBD2B'>{{ scope.row.state}}</span>
          <span v-else-if="scope.row.state == '已受理' || scope.row.state == '未接通' || scope.row.state == '待跟进'" style='color:#3390ff'>{{ scope.row.state}}</span>
          <span v-else-if="scope.row.state == '捣乱申请' || scope.row.state == '已拒批' || scope.row.state == '外地申请'||  scope.row.state == '重复申请'" style='color:#D7962F'>{{ scope.row.state}}</span>
          <span v-else style='color:grey'>{{ scope.row.state}}</span>
          </template>
      </el-table-column>
      <el-table-column prop="remarks" label="备注"></el-table-column>
      <el-table-column prop="entryBank" label="进件银行"></el-table-column>
      <el-table-column label="进件额度" >
        <template slot-scope="scope">{{scope.row.entryQuota | quZheng}}</template>
      </el-table-column> 
      <el-table-column label="放款额度" >
        <template slot-scope="scope">{{scope.row.loanAmount | quZheng}}</template>
      </el-table-column> 
      <el-table-column  label="时间" align="center" sortable>
        <template slot-scope="scope">{{ scope.row.time | formatTime }}</template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination  @size-change="handleSizeChange"  @current-change="handleCurrentChange"  :current-page="pageConfig.currentPage"  :page-sizes="[10, 20 ,50, 100]"  :page-size="pageConfig.pageSize"  layout="total, sizes, prev, pager, next, jumper"  :total="pageConfig.total">
    </el-pagination>
  </div>
</template>

<script>
// 导入时间戳
import moment from 'moment'
export default {
  name: "WorkLog",
  // 数据
  data() {
    return {
      pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now() ;
          }
        }, 
      currentUser:{
        currentName:"",
        currentId:"",
        currentLevel:"",
        position:"",
        currentPhone:""
      },
      //未分割的完整版时间区间
      completeTime: "",
      //时间区间隐藏状态
      isShow:false,
      ShowDaoChu:false,
      //页码参数
      pageConfig:{
        currentPage:1,//当前页
        pageSize:10,//当前单页数据条数
        total:0,//请求到的数据总条数
      },
       //时间选择生成内容
      timeList: [
        { id: "", name: "不限" },
        { id: "today", name: "今日" },
        // { id: "yestoday", name: "昨日" },
        { id: "sevenDay", name: "最近七天" },
        { id: "tomonth", name: "本月" },
        { id: "yesmonth", name: "上月" },
        { id: "customize", name: "自定义" },
      ],
      //客户筛选区域数据
      formLabelAlign: {
        customerName : "", 	//	客户姓名
        userName : "", 	//	顾问姓名
        assistantName : "", 	//	助理姓名
        assistantId : "", 	//	登陆助理ID
        dayType:"tomonth", //默认本月
        beginTime : "", 	//开始时间
        endTime : "",  //	结束时间
      },
      formLabelWidth: '180px',
      // 表格依赖于数据没有数据  会一行都没有
      tableData: []
    };
  },
  methods: {
    //获取客户 List的方法
    getQudaoList(){
      this.$axios
      .get(`/spider/channelLog/getAllChannelLog?assistantId=${this.currentUser.currentid}&customerName=${this.formLabelAlign.customerName}&userName=${this.formLabelAlign.userName}&assistantName=${this.formLabelAlign.assistantName}&beginTime=${this.formLabelAlign.beginTime}&endTime=${this.formLabelAlign.endTime}&currentPage=${this.pageConfig.currentPage}&pageSize=${this.pageConfig.pageSize}`)
      .then(res => {
        // console.log(res);
        if (res.data.messageModel.messageText == "成功!") {
          this.tableData = res.data.dataModel.list;
          this.pageConfig.total = res.data.dataModel.total;
        }else{
          this.$message.error("获取用户失败/(ㄒoㄒ)/~~");
          this.tableData = [];
          this.pageConfig.total = 0;
        }
        })
      .catch(error => {
        console.log(error);
      });
    },
    //清空所有筛选条件的方法
    clearAllCheck(){
        for (let i = 0; i < this.formLabelAlign.length; i++) {
          this.formLabelAlign.formLabelAlign[i] = "";  
        }
        this.completeTime = "" 	//未分割的完整版时间区间
    },
    //判断时间区间是否隐藏
    holderQuJian(vId){
      let obj = {};
      obj = this.timeList.find(item => {
        //这里的fenselectList就是上面遍历的数据源
        return item.id === vId; //筛选出匹配数据
      });
      // console.log(obj.id);
      if (obj.id == "customize") {
        this.isShow = true;
      } else if (obj.id == "today") {
        this.isShow = false;
        this.formLabelAlign.beginTime = moment(new Date()).format("YYYY-MM-DD ") + " " + "00:00:00";
        this.formLabelAlign.endTime = moment(new Date()).format("YYYY-MM-DD ")+ " " + "23:59:59";
        this.completeTime = "";
      } else if (obj.id == "JinLiangDays") {
        this.isShow = false;
        this.formLabelAlign.beginTime = moment(new Date().setTime(new Date().getTime() - 3600 * 1000 * 24 * 1)).format("YYYY-MM-DD ") + " " + "00:00:00";
        this.formLabelAlign.endTime = moment(new Date()).format("YYYY-MM-DD ")+ " " + "23:59:59";
        this.completeTime = "";
      } else if (obj.id == "sevenDay") {
        this.isShow = false;
        this.formLabelAlign.beginTime = moment(new Date().setTime(new Date().getTime() - 3600 * 1000 * 24 * 7)).format("YYYY-MM-DD ") + " " + "00:00:00";
        this.formLabelAlign.endTime = moment(new Date()).format("YYYY-MM-DD ")+ " " + "23:59:59";
        this.completeTime = "";
      } else if (obj.id == "tomonth") {
        this.isShow = false;
        this.formLabelAlign.beginTime = moment(new Date()).format("YYYY-MM-01 ") + " " + "00:00:00";
        this.formLabelAlign.endTime = moment(new Date()).format("YYYY-MM-DD ")+ " " + "23:59:59";
        this.completeTime = "";
      } else if (obj.id == "yesmonth") {
        this.isShow = false;
        this.formLabelAlign.beginTime = moment(moment().month(moment().month() - 1).startOf('month').valueOf()).format("YYYY-MM-DD ") + " " + "00:00:00";
        this.formLabelAlign.endTime = moment(moment().month(moment().month() - 1).endOf('month').valueOf()).format("YYYY-MM-DD ")+ " " + "23:59:59";
        this.completeTime = "";
      } else {
        this.isShow = false;
        this.completeTime = "";
        this.formLabelAlign.beginTime = "";
        this.formLabelAlign.endTime = "";
      }
      // console.log(this.formLabelAlign.beginTime);console.log(this.formLabelAlign.endTime);
    },
    //分页的方法
    handleSizeChange(val) {
      // console.log(val);
      if (this.pageConfig.currentPage != 1) {
        this.pageConfig.currentPage = 1;
        this.pageConfig.pageSize = val;
        this.getQudaoList()
      }else{
        this.pageConfig.pageSize = val;
        this.getQudaoList()
      }
    },
    handleCurrentChange(val) {
      this.pageConfig.currentPage = val;
      this.getQudaoList();
    },
    //查询
    checkCus(){
      if (this.completeTime != "" && this.formLabelAlign.dayType == "customize") {
        this.formLabelAlign.beginTime = (this.completeTime)[0];
        this.formLabelAlign.endTime = (this.completeTime)[1];
        this.formLabelAlign.beginTime = this.formLabelAlign.beginTime + " " + "00:00:00";
        this.teamLogForm.time = this.formLabelAlign.beginTime;
        this.formLabelAlign.endTime = this.formLabelAlign.endTime + " " + "23:59:59";
      }else{
        this.formLabelAlign.beginTime = this.formLabelAlign.beginTime;
        this.formLabelAlign.endTime = this.formLabelAlign.endTime;
      }     
      this.$axios
      .get(`/spider/channelLog/getAllChannelLog?assistantId=${this.currentUser.currentid}&customerName=${this.formLabelAlign.customerName}&userName=${this.formLabelAlign.userName}&assistantName=${this.formLabelAlign.assistantName}&beginTime=${this.formLabelAlign.beginTime}&endTime=${this.formLabelAlign.endTime}&pageSize=10&currentPage=1`)
      .then(res => {
        // console.log(res);
        let code = res.data.messageModel.code;
        if (code == 0) {
          if (res.data.dataModel.total == 0) {
            this.$message('抱歉，没有找到符合搜索条件的数据');
            this.clearAllCheck();
            this.tableData = []
            return false;
          }
          this.$message.success("根据您的搜索条件，已为您找到以下数据(#^.^#)");
          this.tableData = res.data.dataModel.list;
          this.pageConfig.total = res.data.dataModel.total;
        }else{
          this.$message.error(res.data.messageModel.messageText);
          this.clearAllCheck();
        }
      }).catch(error => { console.log(error);});
    },
    //导出表格
    excelDoor(){
      this.$axios({
        method: 'post',
        // url: 'http://139.196.29.59:80//spider/channelLog/excelChannelLog',//临时测试地址 ！！！！！！！！！！！！！
        url: 'https://www.duodaiwang.com/spider/channelLog/excelChannelLog',//正式环境 ！！！！！！！！！！！！！！
        params: {//这个是请求的参数
          assistantId:this.currentUser.currentid,
          customerName:this.formLabelAlign.customerName,
          userName:this.formLabelAlign.userName,
          assistantName:this.formLabelAlign.assistantName,
          beginTime:this.formLabelAlign.beginTime,
          endTime:this.formLabelAlign.endTime,
          currentPage:this.pageConfig.currentPage,
          pageSize:this.pageConfig.pageSize
        },
        responseType: 'blob'
        }).then((res) => {
          // console.log(res);
          const link = document.createElement('a');
          let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'});
          link.style.display = 'none';
          link.href = URL.createObjectURL(blob);
          let time = moment(new Date()).format("YYYY-MM-DD ");
          link.setAttribute('download', this.currentUser.currentName + time + "工作日志数据" +'.xls');
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        }).catch(error => {
        console.log(error)
      })
    },
    //跳转编辑日志
    PushToEditLog(){
      this.$router.push("QuDaoEditLog");
    }
  },
  // 本地过滤器
  filters: {
    formatTime(value) {
      if (value == null) {
        return ""
      }
    //  return moment(value).format("YYYY-MM-DD HH:mm:ss");
      return moment(value).format("YYYY-MM-DD");
    },
    panKong(val) {
      if (val != null) {
        return "--" + val
      }else{
        return ""
      }
    },
    quZheng(val){
      return Number(val);
    }
  },
  created () {
    this.currentUser.currentName = window.sessionStorage.getItem("name");
    this.currentUser.currentid = window.sessionStorage.getItem("id");
    this.currentUser.position = window.sessionStorage.getItem("position");
    if (this.currentUser.position == "主管") {
      this.ShowDaoChu = true;
    }else{
      this.ShowDaoChu = false;
    }
    this.formLabelAlign.beginTime = moment(new Date()).format("YYYY-MM-01 ") + " " + "00:00:00";
    this.formLabelAlign.endTime = moment(new Date()).format("YYYY-MM-DD ")+ " " + "23:59:59";
    this.getQudaoList();
  }
};
</script>

<style lang='scss'>
.WorkLog-container {
  .el-dialog {
    // width: 35%;
    #dateOfBirth {
        /deep/.el-input__inner {
            padding-left: 30px!important;
        }
    }
    .el-form-item {
      // margin-top: 0;
      /deep/.el-form-item__label {
        width: 150px!important;
      }
      /deep/.el-form-item__content {
        margin-left: 150px!important;
      }
    }
  }
  
  //突出隔行的颜色差异
  .el-table {
    font-size: 12px;
    th {
      padding: 0;
    }
    .warning-row {
      background: #fff;
    }
     .success-row {
      background: #D3D3D3;
    }
    td {
      padding: 0;
      border-bottom: 1px solid rgb(211, 205, 205);
    }
     .el-button--mini{
      border: 0;
      padding: 5px 15px;
      margin: 5px 0;
      background: rgba(255,255,255,0.01);
    }
    .toEdit:hover {
      color:skyblue;
    }
  } 
  .el-form-item.BTN {
    /deep/.el-form-item__content{
          margin-left: 20px!important;
    }
  }
  input.el-input__inner {
    width: 170px;
    height: 32px;
    padding-left: 10px;
}

  
// 时间分类框样式
 input.el-input__inner#kinds,
 /deep/input.el-input__inner#time {
    // width: 85px;
    padding-left: 7px;
    height: 32px!important;
}
// 日期选择器
daterange.el-input, .el-date-editor--daterange.el-input__inner, .el-date-editor--timerange.el-input, .el-date-editor--timerange.el-input__inner {
    width: 240px;
    height: 36px;
    vertical-align: middle;
    .el-date-editor .el-range__icon {
    line-height: 27px;
    }
    .el-date-editor .el-range-separator {
    width: 5%;
}
/deep/.block,
#block {
  border: none !important;
  /deep/.el-date-editor--daterange {
    width: 240px !important; 
  }
}
}
.el-form-item {
  display: inline-block;
  margin: 3px 0 3px 10px;
}
.el-form-item:nth-child(n + 6) {
  margin-top: 0;
}
.el-select.time {
  margin-left: 20px;
}
.el-input--suffix .el-input__inner.fanwei {
  padding-right: 30px;
  width: 30px;
}
.filterCondition {
  background-color: #fff;
  margin-bottom: 20px;
}
.check {
  margin-left: 22px;
  padding: 8px 20px;
}
.ell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0;
}
//分页框样式设置（避免页面被覆盖）
    .el-pagination .el-input__inner {
      width: 100px;
    }
}
</style>